

from django.shortcuts import render

# Create your views here.
from rest_framework import status
from rest_framework.generics import GenericAPIView, CreateAPIView
from rest_framework.response import Response
from rest_framework.views import APIView

from users.models import User
from users.serializer import CreateUserserializers


class UserView(CreateAPIView):
    serializer_class = CreateUserserializers
    # def post(self, request):
    #     serializers = self.get_serializer(data = request.data)
    #     serializers.is_valid(raise_exception=True)
    #     serializers.save()
    #     return Response(serializers.data,status=status.HTTP_201_CREATED)




class UsersnameCountView(APIView):
    def get(self, request, username):
        res = User.objects.filter(username=username).count()

        data = {
            'username' : username,
            'count' : res
        }

        return Response(data)



class MobileCountView(APIView):
    def get(self, request, mobile):
        res = User.objects.filter(mobile=mobile).count()
        data = {
            'mobile' : mobile,
            'count' : res
        }

        return Response(data)